<?php

namespace App\Console\Commands\account;


use App\Dep\JingdongTagCategoryDep;
use App\Enum\CommonEnum;
use App\Enum\ContentEnum;
use Illuminate\Console\Command;
use App\Dep\AccountDep;

class ExpCmd extends Command
{
    public $signature = 'account:exp';

    public function handle()
    {
        $accountDep = new AccountDep();
        $resDeal = $accountDep->allNotDel();
        if($resDeal->isEmpty()){
            $this->log("not del account is empty");
            return false;
        }

        $currentTime = time();
        $resDeal->each(function($account) use ($currentTime,$accountDep){
           if($account->platform == ContentEnum::PLATFORM_JINGDONG && $currentTime - strtotime($account->cookie_at) > 60 * 60 * 24 && $account->is_cookie_exp == CommonEnum::NO){
               $accountDep->edit($account->id,['is_cookie_exp'=>CommonEnum::YES]);
               $this->log('jingdong exp ' . $account->id);
           }
            if($account->platform == ContentEnum::PLATFORM_XIAOHONGSHU && $currentTime - strtotime($account->cookie_at) > 60 * 60 * 24 && $account->is_cookie_exp == CommonEnum::NO){
                $accountDep->edit($account->id,['is_cookie_exp'=>CommonEnum::YES]);
                $this->log('xiaohongshu exp ' . $account->id);
            }
//            if($account->platform == ContentEnum::PLATFORM_TAOBAO && $currentTime - strtotime($account->token_at) > 60 * 60 * 24 * 180 && $account->is_token_exp == CommonEnum::NO){
//                $accountDep->edit($account->id,['is_token_exp'=>CommonEnum::YES]);
//                $this->log('taobao exp ' . $account->id);
//            }
        });
    }

    private function log($msg,$context = []){
        $this->info("account_exp: {$msg}");
        log_daily("account_exp")->info($msg,$context);
    }
}
